import { onMounted, reactive, watch } from 'vue';

export default function importConfig(props, { emit }) {
  const { collection, btns } = props;

  const base = reactive<any>({
    collectionCopy: null,
    spaceVal: 0,
  });

  const init = () => {
    base.collectionCopy = props.collection;
  };

  const emitCommand = () => {
    // emit('update:config', base.collection);
    console.log(base.collectionCopy);
    emit('tapDate', base.collectionCopy);
  };

  const searchInit = () => {
    console.log('111111111');
    emitCommand();
  };

  const reset = () => {
    base.collectionCopy.forEach((item) => {
      item.value = null;
    });
    emitCommand();
  };

  const btnClick = (name) => {
    if (name == '查询') {
      searchInit();
    } else if (name == '重置') {
      reset();
    } else {
      searchInit();
    }
  };
  // watch(base.collectionCopy,()=>{
  // })
  onMounted(() => {
    // let n1 = (Math.ceil(collection.length / 3)) * 52 - 20;
    // let n2 = props.btns.length * 32;
    // base.spaceVal = Math.ceil((n1 - n2) / (props.btns.length - 1));
  });

  return {
    base,
    init,
    searchInit,
    reset,
    btnClick,
  };
}
